/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package olimpus.per;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
 *
 * @author
 * Leonardo
 */
public class FuncionesPer
{
    public static long obtenerNumerador(Connection con, String xId, String xTabla) throws Exception
   {
        try
        {
            String query = "select "
                            + "    isnull(max("+xId+"), 0) + 1 as NUMERADOR "
                            + "from " + xTabla;
            
            PreparedStatement st=con.prepareStatement(query);

            System.out.println("query = " + query);

            ResultSet resultado = st.executeQuery();

            if (resultado.next())
            {
                return resultado.getInt("NUMERADOR");
            }
        }
        catch (SQLException ex)
        {
            throw new Exception("Persistencia--> " + ex.getMessage());
        }
        
        return 1;
   }
}
